

from app import db
from datetime import datetime


# 用户表
class User(db.Model):
    __tablename__ = "user"
    uid = db.Column(db.BigInteger, primary_key=True, comment="用户id")
    name = db.Column(db.String(100), nullable=False, comment="昵称")
    mobile = db.Column(db.String(11), comment='手机号')
    password_hash = db.Column(db.String(256), comment='密码')
    avatar = db.Column(db.String(256), comment='头像')
    member = db.Column(db.Integer, comment='会员等级')
    balance = db.Column(db.DECIMAL(12, 2), comment='总金额')
    record = db.relationship('Record', backref='user')

# 课程表
class Course(db.Model):
    __tablename__ = "course"
    cid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='课程ID')
    name = db.Column(db.String(32), comment='课程名称')
    image = db.Column(db.String(128), comment='图片')
    desc = db.Column(db.String(128), comment='描述')
    attention = db.Column(db.Integer, comment='关注总数')
    browse = db.Column(db.Integer, comment='浏览次数')
    kind = db.relationship('Kind', backref='course')
    vipcourse = db.relationship('VipCourse', backref='course')

# vip课程表
class VipCourse(db.Model):
    __tablename__ = "vipcourse"
    vid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='vip课程ID')
    user_id = db.Column(db.Integer, db.ForeignKey("user.uid"), nullable=False)
    course_id = db.Column(db.Integer, db.ForeignKey('course.cid'), nullable=False)

#vip购买记录表
class VipBuy(db.Model):
    uid = db.Column(db.BigInteger, primary_key=True, comment="用户id")
    age_limit = db.Column(auto_now_add=True, verbose_name='购买年限')
    money = db.Column(db.Integer,comment="金额")
    discount = db.Column(db.Integer,comment="折扣")
    sum = db.Column(db.Integer,comment="实际金额")
    steate = db.Column(default=0, choices=((0, '待支付'), (1, '已支付'), (2, '未支付')))



# 类别表
class Kind(db.Model):
    __tablename__ = "kind"
    kid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='类别ID')
    course_id = db.Column(db.Integer, db.ForeignKey('course.cid'), nullable=False)
    name = db.Column(db.String(32), comment='类别名')

# 类型表
class Type(db.Model):
    __tablename__ = "type"
    tid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='类型表')
    name = db.Column(db.String(32), comment='类型名')

# 标签表
class Label(db.Model):
    __tablename__ = "label"
    lid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='标签ID')
    name = db.Column(db.String(32), nullable=False)
# 标签表
class Label1(db.Model):
    __tablename__ = "label"
    lid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='标签ID')
    name = db.Column(db.String(32), comment='标签名')


class CourseLabel(db.Model):
    __tablename__ = 'courselabel'
    clid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='课程标签ID')
    course_id = db.Column(db.Integer, db.ForeignKey('course.cid'), nullable=False)
    label_id = db.Column(db.Integer, db.ForeignKey('label.lid'))

# vip记录表
class Record(db.Model):
    __tablename__ = "record"
    rid = db.Column(db.Integer, primary_key=True, comment='vipID')
    user_id = db.Column(db.Integer, db.ForeignKey("user.uid"), nullable=False)
    begin_date = db.Column(db.DateTime, nullable=False, comment='开始时间')
    end_date = db.Column(db.DateTime, nullable=False, comment='结束时间')



#订单表
class Order(db.Model):
    lid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='标签ID')
    order_id = db.Column.CharField(max_length=100, primary_key=True, verbose_name='订单号')
    user_id = db.Column(db.BigInteger, primary_key=True, comment="用户id")
    course_id = db.Column(db.BigInteger, primary_key=True, comment="课程id")
    sum = db.Column(db.Integer,comment="数量")
    unit = db.Column(db.Integer,comment="单价")
    total = db.Column(db.Integer, comment="总价")
    state = db.Column(db.String(100),comment="状态")
    alipay = db.Column(db.String(100),comment="支付宝流水号")

#购物车
class Shopping(db.Model):
    uid = db.Column(db.BigInteger, primary_key=True, comment="用户id")
    course_id = db.Column(db.BigInteger, primary_key=True, comment="课程id")
    sum = db.Column(db.Integer, comment="数量")

#训练营课程表
class Training(db.Model):
    lid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='标签ID')
    introduce = db.Column(db.String(1000), nullable=False, comment="介绍")
    image = db.Column(db.String(128), comment='图片')
    price = db.Column(db.Integer,comment="价格")
    inventory = db.Column(db.String(100),comment="库存")

# 评论分类表
class Comment_class(db.Model):
    cid = db.Column(db.Integer, primary_key=True, autoincrement=True,)
    name = db.Column(db.String(32), comment='分类名')
#评价表
class Comment (db.Model):
    tid = db.Column(db.Integer, primary_key=True, autoincrement=True,)
    title = db.Column(db.String(32), comment='标题')
    Reply_number = db.Column(db.Integer, comment='回复数')
    Check_number = db.Column(db.Integer, comment='总查看数')
    Userid = db.Column(db.Integer, db.ForeignKey("user.uid"), comment='用户id')
    Last_reply = db.Column(db.DateTime, comment='最后回复时间')
    pid = db.Column(db.Integer, comment='')
    top = db.Column(db.Integer, comment='是否置顶')

#章节表
class Section(db.Model):
    cid = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='标签ID')
    name = db.Column(db.String(100), nullable=False, comment="名称")
    pitch = db.Integer(db.String(100), comment="节数")
    img = db.Column(db.String(128), comment='视频')
    course_id = db.Column(db.Integer, db.ForeignKey('course.cid'),cmment="课程id")


#第三方登录
class Register(db.Model):
    id = db.Column(db.BigInteger, primary_key=True, comment="用户id")
    platfrom = db.Column(default=1, choices=((1, '支付宝'), (2, '微信'),(3,'QQ')), verbose_name='第三方登录方式')
    uid = db.Column(db.BigInteger, comment="Uid")

db.create_all()